Class holding information about a string, with ownership over the data. More...
Public Member Functions | |
String () | |
String (const char *data) | |
String (unsigned long long size) | |
String (const char *data, unsigned long long size) | |
String (const StringView &view) | |
String (const String &other) | |
String (String &&other) noexcept | |
~String () | |
char * | getData () const |
unsigned long long | getSize () const |
bool | empty () const |
char & | front () |
char & | back () |
void | clear () |
void | resize (unsigned long long size) |
String & | operator= (const char *data) |
String & | operator= (const StringView &other) |
String & | operator= (const String &other) |
String & | operator= (String &&other) noexcept |
const char | operator[] (unsigned long long index) const |
char & | operator[] (unsigned long long index) |
void | operator+= (char value) |
void | operator+= (const StringView &other) |
nkMemory::String | operator+ (const StringView &other) |
bool | operator== (const char *other) const |
bool | operator== (const String &other) const |
bool | operator== (const StringView &other) const |
String (const std::string &str) | |
String (const std::string_view &str) | |
operator std::string () const | |
operator std::string_view () const | |
Class holding information about a string, with ownership over the data.
This class will abstract a chain of characters and offer some utility to help manipulating them. The aim of this class is not to replace std::string within a codebase, but rather to offer a safe data exchange class from an app to the dlls, and the other way around. This class being fully exported, it doesn't suffer from the caveats a template can have in such situations.
To help in this dialog between app and dlls, the class is thought to be as transparent as possible between const char*, std::string and other widespread way of representing strings. Typical usage would just be to use standard structures in your app and benefit from the automatic converions from one type to another.
The String class will copy over memory and keep it in its own safe allocation. If memory safety is required, use this class. However, this can be slower as memory needs to be allocated and shuffled around. Unless this is required, prefer to use the StringView variant.
nkMemory::String::String | ( | ) |
Default constructor. Will default to a nullptr data and a size of 0.
nkMemory::String::String | ( | const char * | data | ) |
Const char* constructor. Provided memory location will be copied based on its length. Be sure provided data is null-terminated.
data | The pointer to the chain of characters to take over. |
nkMemory::String::String | ( | unsigned long long | size | ) |
Pre-allocation constructor. Data will be allocated depending on the size requested, and set to 0.
size | The size of the chain to create, in number of chars. |
nkMemory::String::String | ( | const char * | data, |
unsigned long long | size | ||
) |
Guided const char* constructor. Provided memory location will be copied based on the size given. Prefer this constructor over the const char* constructor if you know the size required.
data | The pointer to the chain of characters to take over. |
size | The size of the chain provided, in number of chars. |
nkMemory::String::String | ( | const StringView & | view | ) |
View constructor. Memory location pointed by view will be copied over.
view | The view to copy the memory from. |
nkMemory::String::String | ( | const String & | other | ) |
Copy constructor.
other | The string to copy from. |
|
noexcept |
Move constructor.
other | The string to move over. |
nkMemory::String::~String | ( | ) |
Destructor.
nkMemory::String::String | ( | const std::string & | str | ) |
Standard string constructor. The string provided will be copied over.
str | The string to copy. |
nkMemory::String::String | ( | const std::string_view & | str | ) |
Standard string view constructor. The view provided will be copied over.
str | The view to copy. |
char* nkMemory::String::getData | ( | ) | const |
unsigned long long nkMemory::String::getSize | ( | ) | const |
bool nkMemory::String::empty | ( | ) | const |
char& nkMemory::String::front | ( | ) |
char& nkMemory::String::back | ( | ) |
void nkMemory::String::clear | ( | ) |
Clears the string and frees its memory, returning it to its default state.
void nkMemory::String::resize | ( | unsigned long long | size | ) |
Resizes the internal memory of the string. Existing chars will be kept, while newly introduced ones will be set to 0.
size | The new size the string should take, in number of chars. |
String& nkMemory::String::operator= | ( | const char * | data | ) |
Const char* assignment operator.
data | The pointer over the memory to copy. |
String& nkMemory::String::operator= | ( | const StringView & | other | ) |
View assignment operator.
other | The view over memory to copy. |
String copy assignment operator.
other | The string to copy. |
String move assignment operator.
other | The string to move over. |
const char nkMemory::String::operator[] | ( | unsigned long long | index | ) | const |
Const access operator.
index | The index of the char to access. |
char& nkMemory::String::operator[] | ( | unsigned long long | index | ) |
Access operator.
index | The index of the char to access. |
void nkMemory::String::operator+= | ( | char | value | ) |
Char append operator.
value | The char to append to the string. |
void nkMemory::String::operator+= | ( | const StringView & | other | ) |
View append operator.
other | The view to append to the string. |
nkMemory::String nkMemory::String::operator+ | ( | const StringView & | other | ) |
View concatenation operator.
other | The view to concatenate with. |
bool nkMemory::String::operator== | ( | const char * | other | ) | const |
Const char* equality operator.
other | The const char* to check equality with. |
bool nkMemory::String::operator== | ( | const String & | other | ) | const |
String equality operator.
other | The string to check equality with. |
bool nkMemory::String::operator== | ( | const StringView & | other | ) | const |
View equality operator.
other | The view to check equality with. |
nkMemory::String::operator std::string | ( | ) | const |
Conversion operator, to std::string.
nkMemory::String::operator std::string_view | ( | ) | const |
Conversion operator, to std::string_view.